package com.yuncommunity.runcircle.item;

import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.model.LatLng;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.oldfeel.base.BaseItem;

import java.text.DecimalFormat;

/**
 * Created by oldfeel on 11/23/15.
 */
@DatabaseTable
public class LocationItem extends BaseItem {
    public static final int TYPE_START = 1; // 开始点
    public static final int TYPE_END = 2; // 结束点
    @DatabaseField(generatedId = true)
    public int _id;
    @DatabaseField
    public double lat;
    @DatabaseField
    public double lon;
    @DatabaseField
    public double distance;
    @DatabaseField
    public long time;
    @DatabaseField
    public int userId;
    @DatabaseField
    public int type;
    @DatabaseField
    public String date;
    @DatabaseField // 速度(km/h)
    public double speed;
    @DatabaseField // 持续时间(毫秒)
    public long duration;
    @DatabaseField // 本次跑步的总距离 (单位:米)
    public double allDistance;
    @DatabaseField // 系统记录的步数,开始点为系统步数,结束点为跑步步数
    public int step;
    @DatabaseField
    public String id;

    public double initDistance(LocationItem lastItem) {
        LatLng startLatlng = new LatLng(lastItem.lat, lastItem.lon);
        LatLng endLatlng = new LatLng(lat, lon);
        return AMapUtils.calculateLineDistance(startLatlng, endLatlng);
    }

    public CharSequence getSpeedKMH() {
        return new DecimalFormat("0.00").format(speed * 60 / 1000) + "km/h";
    }

    public CharSequence getDistanceKM() {
        return new DecimalFormat("0.00").format(distance / 1000);
    }

    public CharSequence getSpeedMKM() {
        return new DecimalFormat("0.00").format(speed * 60 / 1000) + "min/km";
    }
}
